<?php
use think\Db;
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 流年 <liu21st@gmail.com>
// +----------------------------------------------------------------------

//公共单数据查询方法
function CheckAuthority($url) {
    $wyrolelist_hpltply = session("wyrolelist_lvtuan");
    $result = false;
    if ($wyrolelist_hpltply == null) {
        return $result;
    }
    foreach ($wyrolelist_hpltply as $key => $value) {
        $Matchingstr = "|".$value["af_furl"]."|is";

        if (preg_match($Matchingstr, $url)  ) {
            $result = true;
            break;
        }
    }
    return $result;
}

//写入操作日志
function addOperation($parr){

    $admin=session('Admin_user_hplxtws');
    $arr=array(
        'ao_record' =>  $parr['ao_record'],
        'admin_id'  =>  $admin['admin_id'],
        'ao_addtime'=>  Date('Y-m-d H:i:s')
    );
    $b=Db::table('lt_admin_operation')->insert($arr);
    return $b;
}

//图片上传
function uploadsApi($file){
    try {
        $move = ROOT_PATH . 'public' . DS . 'uploads/img';
        $info =$file->validate(['ext'=>'jpg,png,gif'])->move($move);
        if(!$info){
            // 上传失败获取错误信息
            $error = $file->getError();
            $response = messageInfo('1001', $error);
            return $response;
        }
        $url     = config('tempredirect_url').'uploads/img/'.$info->getSaveName();
        $response = messageInfo('1002','上传成功',$url);
    } catch (\Exception  $e) {
        $response = messageInfo('101','服务器错误');
    }
    return $response;
}


//将对象转换成数组
function object2array($object) {
    if (is_object($object)) {
        foreach ($object as $key => $value) {
            $array[$key] = $value;
        }
    }
    else {
        $array = $object;
    }
    return $array;
}


//产品价格/原价/名称
function product_name($type =11){
    $name = '';
    switch($type){
        case 11:
            $name          = '法律顾问基础套餐';
            break;
        case 12:
            $name           = '法律顾问标准套餐';
            break;
        case 13:
            $name           = '法律顾问专家套餐';
            break;
        case 14:
            $name           = '法律顾问尊享套餐';
            break;
        case 2:
            $name          = '律师函';
            break;
        case 3:
            $name           = '股权架构设计';
            break;
        case 4:
            $name          = '股权激励方案';
            break;
        case 5:
            $name           = '投融资顾问';
            break;
        case 6:
            $name          = '企业劳动风险防范专项套餐';
            break;
        case 7:
            $name           = '教你打官司';
            break;
        default:
            $name           = '其它';
            break;
    }
    return $name;
}


